<?php

namespace App\Http\Models\Permissions;

use Illuminate\Foundation\Http\FormRequest;

/*
 * PermissionsFrom  权限表单验证
 *
 * rules() 权限验证规则
 * messages() 权限验证提示信息
 *
 * @author Jinfeihu
 */

class PermissionFrom extends FormRequest {

    public function authorize() {
        return true;
    }

    public function rules() {
        //注意表名如果有s的话尽量去掉
        $id = $this->route("permission");
        if ($id) {
            $id = decryptUrl($id);
        }
        return [
            'permissions_name' => 'required|max:30',
            'urls' => 'required|max:100|unique:permissions,urls,' . $id,
        ];
    }

    public function messages() {
        return [
            'permissions_name.required' => '权限名称不能为空',
            'permissions_name.max' => '权限名称不能超过30个字符',
            'urls.required' => "路由不能为空",
            'urls.unique' => '路由名称已存在',
            'urls.max' => "路由不能超过100个字符",
        ];
    }

}
